package com.hvgroup.modules.sanic.repository;

import com.hvgroup.modules.sanic.domain.po.LlmRolePermission;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface LlmRolePermissionRepository extends JpaRepository<LlmRolePermission, Long>, JpaSpecificationExecutor<LlmRolePermission> {

    @Query(value = "SELECT perm.* FROM `llm_role_permission` perm " +
            "LEFT JOIN sys_role role on perm.role_id = role.role_id " +
            "LEFT JOIN sys_users_roles ur ON ur.user_id = role.role_id " +
            "WHERE ur.user_id = ?1", nativeQuery = true)
    List<LlmRolePermission> findByUserId(Long userId);

    @Query(value = "SELECT perm.* FROM `llm_role_permission` perm " +
            "LEFT JOIN sys_role role on perm.role_id = role.role_id " +
            "LEFT JOIN sys_users_roles ur ON ur.user_id = role.role_id " +
            "WHERE ur.user_id = ?1 AND perm.platform_id = ?2 ", nativeQuery = true)
    List<LlmRolePermission> findByUserId(Long userId, Long platformId);

}
